package com.orange.adminapi.controller.mallArea;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.orange.core.service.mallArea.MallAreaService;
import com.orange.core.pojo.BR;
import com.orange.core.pojo.PageReqDto;
import com.orange.core.pojo.R;
import com.orange.core.pojo.entity.mallArea.dto.MallAreaDTO;
import com.orange.core.pojo.entity.mallArea.vo.MallAreaFloorVO;
import com.orange.core.pojo.entity.mallArea.vo.MallAreaVO;
import com.orange.core.pojo.req.mallArea.MallAreaPageReq;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>ClassName:MallAreaController</p>
 * <p>Description: 商场区域controller</p>
 * <p>Author: lwm</p>
 * <p>Date: 2025/5/24 16:57</p>
 */
@RequiredArgsConstructor
@RestController
@RequestMapping("/mallArea")
public class MallAreaController {

    private final MallAreaService mallAreaService;


    /**
     * 商场区列表查询
     * @return
     */
    /*@PreAuthorize("hasAuthority(T(com.orange.core.pojo.enums.EPermission).MALL_AREA_LIST.permission.identifier)")
    @GetMapping("/list")
    public R<List<MallAreaVO>> list(){
        List<MallAreaVO> mallAreaVOList = mallAreaService.mallAreaList();
        return R.ok(mallAreaVOList);
    }*/

    /**
     * 商场区域分页查询
     * @param pageReqDto
     * @return
     */
    @PreAuthorize("hasAuthority(T(com.orange.core.pojo.enums.EPermission).MALL_AREA_LIST.permission.identifier)")
    @PostMapping("/page")
    public R<Page<MallAreaVO>> page(@RequestBody PageReqDto<MallAreaPageReq> pageReqDto){
        Page<MallAreaVO> page = mallAreaService.page(pageReqDto);
        return R.ok(page);
    }

    /**
     * 商场区域详情
     * @param id
     * @return
     */
    @PreAuthorize("hasAuthority(T(com.orange.core.pojo.enums.EPermission).MALL_AREA_INFO.permission.identifier)")
    @GetMapping("/info/{id}")
    public R<MallAreaVO> info(@PathVariable("id")Integer id){
        return R.ok(mallAreaService.info(id));
    }

    /**
     * 新端商场区域
     * @param mallAreaDTO
     * @return
     */
    @PreAuthorize("hasAuthority(T(com.orange.core.pojo.enums.EPermission).MALL_AREA_SAVE.permission.identifier)")
    @PostMapping
    public R<Boolean> save(@RequestBody @Validated MallAreaDTO mallAreaDTO){
        return BR.result(mallAreaService.save(mallAreaDTO));
    }

    /**
     * 修改商场区域
     * @param mallAreaDTO
     * @return
     */
    @PreAuthorize("hasAuthority(T(com.orange.core.pojo.enums.EPermission).MALL_AREA_UPDATE.permission.identifier)")
    @PutMapping
    public R<Boolean> update(@RequestBody @Validated MallAreaDTO mallAreaDTO){
        return BR.result(mallAreaService.update(mallAreaDTO));
    }

    /**
     * 批量删除商场区域
     * @param ids
     * @return
     */
    @PreAuthorize("hasAuthority(T(com.orange.core.pojo.enums.EPermission).MALL_AREA_DELETE.permission.identifier)")
    @DeleteMapping("/{ids}")
    public R<Boolean> remove(@PathVariable("ids") Integer[] ids){
        return BR.result(mallAreaService.deleteMallAreaByIds(ids));
    }


    /**
     * 区域加楼层返给前端使用
     * @return
     */
    @PreAuthorize("hasAuthority(T(com.orange.core.pojo.enums.EPermission).MALL_AREA_LIST.permission.identifier)")
    @GetMapping("/list")
    public R<List<MallAreaFloorVO>> mallAreaFloorList(){
        return R.ok(mallAreaService.mallAreaFloorList());
    }
}
